#include "dialog.ch"

//----------------------------------------------------------------------------//

CLASS RadioBtn FROM Visual

   DATA   cText
   DATA   lChecked
   DATA   cClrHotKey

   METHOD New        // RbtNew
   METHOD Display    // RbtDisplay
   METHOD SetFocus   // RbtSetFocus
   METHOD KeyPressed // RbtKeyPressed
   METHOD Click      // RbtClick
   METHOD cGetHotKey // cRbtGetHotKey
   METHOD SetText    // RbtSetText

ENDCLASS

//----------------------------------------------------------------------------//

METHOD New( nRow, nCol, cText, nId, cMessage )

   DEFAULT nRow = 0, nCol = 0, cText = "&RadioButton", nId = 0, cMessage = ""

   ::Parent:New()

   ::nTop       = nRow
   ::nLeft      = nCol
   ::nBottom    = nRow
   ::nRight     = nCol + 5 + nLabelLen( cText ) - 1
   ::nId        = nId
   ::cText      = cText
   ::cMessage   = cMessage
   ::lChecked   = .f.
   ::cClrNormal = "N/BG"
   ::cClrHotKey = "GR+" + SubStr( ::cClrNormal, At( "/", ::cClrNormal ) )

return Self

//----------------------------------------------------------------------------//

METHOD Display()

   local nMCrsOld := SetMCursor()

   SetMCursor( .f. )
   SayHot( ::nAbsTop(), ::nAbsLeft(),;
           " (" + If( ::lChecked, Chr( 7 ), " " ) + ") " + ::cText,;
           If( ! ::lActive, ::cClrInactive,;
               If( ::lFocused, ::cClrFocus, ::cClrNormal ) ),;
               If( ::lFocused, SubStr( ::cClrHotKey, 1, At( "/", ::cClrHotKey ) - 1 ) + ;
                   SubStr( ::cClrFocus, At( "/", ::cClrFocus ) ), ::cClrHotKey ) )
   SetMCursor( nMCrsOld )

return nil

//----------------------------------------------------------------------------//

METHOD SetFocus( lOnOff, cClrFocus )

   ::Parent:SetFocus( lOnOff, cClrFocus )
   ::Display()

return nil

//----------------------------------------------------------------------------//

METHOD KeyPressed( nKey )

   ::lChecked = ! ::lChecked
   ::Display()
   if ::oParent != nil
      ::oParent:RbtChanged( Self )
   endif

return nil

//----------------------------------------------------------------------------//

METHOD Click( nRow, nCol )

   ::lChecked = ! ::lChecked
   ::Display()
   if ::oParent != nil
      ::oParent:RbtChanged( Self )
   endif

return nil

//----------------------------------------------------------------------------//

METHOD cGetHotKey()

   local nAt := At( "&", ::cText )

return If( nAt != 0, SubStr( ::cText, nAt + 1, 1 ), "" )

//----------------------------------------------------------------------------//

METHOD SetText( cText )

   ::cText  = cText
   ::nRight = ::nLeft + 5 + nLabelLen( cText ) - 1

return nil

//----------------------------------------------------------------------------//
